TH2D* makeHisto2(string filePath, int ix, int iy, double nx, double ny, double x0 = 0, double y0 = 0) {
	TH2D* histo = new TH2D("histo0", "Photoelectron yield by position;x;y;count", ix, -nx-x0, nx-x0, iy, -ny-y0, ny-y0);
	TH2D* histo1 = new TH2D("histo1", "Npe avg;x;y;count", ix, -nx-x0, nx-x0, iy, -ny-y0, ny-y0);

	ifstream ifile(filePath.c_str());

	int buffSize = 128;
	char* buffer = new char[buffSize];
	ifile.getline(buffer, buffSize);

	string temps, xs, ys, cs;

	for (int i = 0; !ifile.eof(); i++) {
		temps = buffer;

		size_t pos1 = temps.find('\t', 0);
		size_t pos2 = temps.find('\t', pos1 + 1);

		xs = temps.substr(0, pos1);
		ys = temps.substr(pos1 + 1, pos2 - pos1);
		cs = temps.substr(pos2 + 1, temps.size() - 1 - pos2);

		histo->Fill(atof(xs.c_str()),atof(ys.c_str()), atof(cs.c_str()));
		histo1->Fill(atof(xs.c_str()),atof(ys.c_str()), 1.0);

		ifile.getline(buffer, buffSize);
	}

	ifile.close();
	delete[] buffer;

	for(int i = 0;i < ix;i++) {
		for(int j = 0;j < iy;j++) {
			double count = histo1->GetBinContent(i+1,j+1);
			if (count > 0)
				histo->SetBinContent(i+1,j+1,histo->GetBinContent(i+1,j+1)/count);		
		}
	}

	return histo;
}
